const cloud = require('wx-server-sdk');
cloud.init();

exports.main = async (event, context) => {
  const db = cloud.database();
  const _ = db.command;
  const { openid, stockCode } = event;
console.log(stockCode)
console.log(openid)
try {
  const result = await db.collection('selectedStock').where({ openid }).update({
    data: {
      stockCodes: _.pull(stockCode)  // 使用 _.pull 来删除 stockCode
    }
  });

  if (result.stats.updated === 0) {
    throw new Error('失败');
  }

  return {
    success: true,
    data: result
  };
} catch (error) {
  console.error('Error removing stock:', error);
  return {
    success: false,
    error: error.message
  };
}
};
